package action;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.hibernate.Session;
import org.hibernate.Transaction;

import sessionfactory.HibernateSessionFactory;

import classes.Droit;
import classes.Employe;

import sessionfactory.HibernateSessionFactory;
public class ModifiedAction extends Action {

	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
	throws Exception 
	{
		Session session = HibernateSessionFactory.getSessionFactory().openSession();
		
		String req = "FROM Employe as emp WHERE emp.id = " + request.getParameter("deleteempl");
		Transaction tx = session.beginTransaction();
		List<Employe> l = session.createQuery(req).list();
		
	
		req = "UPDATE Employe SET prenom ='" + request.getParameter("prenom") + "' WHERE id=" + request.getParameter("deleteempl");
		session.createQuery(req).executeUpdate();
		req = "UPDATE Employe SET nom ='" + request.getParameter("nom") + "' WHERE id=" + request.getParameter("deleteempl");
		session.createQuery(req).executeUpdate();
		req = "UPDATE Employe SET login ='" + request.getParameter("login") + "' WHERE id=" + request.getParameter("deleteempl");
		session.createQuery(req).executeUpdate();
		req = "UPDATE Employe SET status ='" + request.getParameter("status") + "' WHERE id=" + request.getParameter("deleteempl");
		session.createQuery(req).executeUpdate();
		
		
		tx.commit ();
		
		return mapping.findForward("Success");
	}
}